package org.chen.spring.cloud.finchley.hystrix.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;

/**
 * @author chensj
 * @date 2020-02-08 13:16
 */
@Service
public class UserService {

  /**
   * 用户获取
   *
   * @param username 用户登录名
   * @return
   * @throws Exception 登录异常
   */
  @HystrixCommand(fallbackMethod = "defaultUser")
  public String getUser(String username) throws Exception {
    if (username.equals("str")) {
      return "this is a real user";
    } else {
      throw new Exception();
    }
  }
  /**
   * 用户获取 异常请求回调
   *
   * @param username 用户登录名
   * @return
   * @throws Exception 登录异常
   */
  public String defaultUser(String username) {
    return "The User does not exists in this system";
  }
}
